using System.Collections;
using UnityEngine;

internal class PhysicalDrag : IPhysicalSupport
{
	private Rigidbody m_Rigidbody;

	private Vector3 m_Velocity;

	private Vector3 m_AngularVelocity;

	private float m_VelocityDrag;

	private float m_AngularVelocityDrag;

	private SphereCollider sphereCollider;

	private float m_Radius;

	public void Init(Hashtable table)
	{
		m_Rigidbody = (Rigidbody)table["Rigidbody"];
		m_VelocityDrag = (float)table["VelocityDrag"];
		m_AngularVelocityDrag = (float)table["AngularVelocityDrag"];
		sphereCollider = m_Rigidbody.GetComponent<SphereCollider>();
		float radius = sphereCollider.radius;
		Vector3 localScale = m_Rigidbody.transform.localScale;
		m_Radius = radius * localScale.x;
	}

	public void FixedCall()
	{
		if (!m_Rigidbody.IsSleeping() && !m_Rigidbody.isKinematic)
		{
			VelocityDrag();
			AngularVelocityDrag();
		}
	}

	private void VelocityDrag()
	{
		if (!m_Rigidbody.isKinematic)
		{
			m_Velocity = m_Rigidbody.velocity;
			float num = m_Velocity.magnitude - m_VelocityDrag * Time.fixedDeltaTime;
			if (num <= 0f)
			{
				m_Rigidbody.velocity = Vector3.zero;
			}
			else
			{
				m_Rigidbody.velocity = m_Velocity.normalized * num;
			}
		}
	}

	private void AngularVelocityDrag()
	{
		if (!m_Rigidbody.isKinematic)
		{
			m_AngularVelocity = m_Rigidbody.angularVelocity;
			float num = (!(Mathf.Abs(m_AngularVelocity.y) < 10f)) ? (m_AngularVelocity.magnitude * 0.1f) : 1f;
			float num2 = ConstantData.angularDrag * Time.fixedDeltaTime * num;
			float num3 = Mathf.Abs(m_AngularVelocity.y) - num2;
			if (num3 <= 0f)
			{
				m_AngularVelocity.y = 0f;
			}
			else
			{
				m_AngularVelocity.y = ((!(m_AngularVelocity.y < 0f)) ? num3 : (0f - num3));
			}
			m_Rigidbody.angularVelocity = m_AngularVelocity;
		}
	}
}
